//
//  BundleDescription.swift
//  BundleDescription
//
//  Created by ddev CLI Tools on 2022/8/17.
//

import Foundation
import DTKModuleDescription

let bundle = Module(
    // 应用名称
    name: "DTKMapBundle",

    // 应用唯一标识，在 集成中心->集成应用详情->基础信息->集成标识 中获取
//    id: "mrbl7txu",
    id: "dn9zdb3v",

    // 应用版本号
    version: "1",
    
    // JSAPI描述
    jsapis: [
        .jsapi("map", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("getLocation", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("openLocation", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("chooseImage", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("getWifiInfo", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("getDeviceInfo", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("getGeolocation", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("toSetPage", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("getGPSLocation", handlerClass: "DTKMapBundleMapJSAPI"),
        .jsapi("getGeoKey", handlerClass: "DTKMapBundleMapJSAPI"),
    ],

    // 扩展实现列表，可选
    extensions: [
        // Fill extensions in this Array as follows...
        //.extensionIn("im_message$im_message_long_press", handlerClass: "DGXXXIMLongPressExtensionItem"),
        //.extensionIn("im_conversation$im_conversation_plus", handlerClass: "DGXXXIMPlusExtensionItem"),
        .extensionIn("location_container$location", handlerClass: "DTKMapBundle", name: "Location", description: "定位功能"),
        .extensionIn("location_container$map", handlerClass: "DTKMapBundle", name: "Map" ,description: "地图功能"),
    ],
    /// 2.x的项目，必须打开这个开关，否则JSAPI不生效
    isCompatibleBundle: true
)

@main
struct DTKMapBundleDescription {
    static func main() {
        let filePath: String = #file
    
        // bundle.plist is the file that represent this bundle artifact, dingtalk app will read it to load bundle artifact.
        // bundle.plist is auto created by ddev command line tool, please check below bundle.plist path.
        // DTKMapBundle/Assets/DTKMapBundle.bundle/bundle.plist
        let bundlePlistPath = filePath.deletingLastPathComponent.appendingPathComponent("DTKMapBundle/Assets/DTKMapBundle.bundle/bundle.plist")
        try! bundle.save(at: bundlePlistPath)
        
        // Manifest.json is the file that developer can upload to 'IntegrationCenter', Manifest.json describe all infos that 'IntegrationCenter' wants to know.
        // Manifest.json is auto created by ddev
        // DTKMapBundle/Manifest.json
        let manifestPath = filePath.deletingLastPathComponent.appendingPathComponent("Manifest.json")
        try! bundle.manifest.save(at: manifestPath)
    }
}
